#ifndef CAMERACALIBRATOR_H
#define CAMERACALIBRATOR_H

#include <vector>
#include <iostream>

#include <opencv2/core/core.hpp>
#include <opencv2/imgproc/imgproc.hpp>
#include <opencv2/calib3d/calib3d.hpp>
#include <opencv2/highgui/highgui.hpp>

class CameraCalibrator
{
 
    std::vector< std::vector<cv::Point3f> > objectPoints;

    std::vector< std::vector<cv::Point2f> > imagePoints;

    cv::Mat cameraMatrix; 
    cv::Mat distCoeffs;   
   
    int flag;

    cv::Mat map1, map2;
    bool mustInitUndistort;

  public:
    CameraCalibrator() : flag(0), mustInitUndistort(true) {}

    int addChessboardPoints(const std::vector<std::string> &filelist, cv::Size &boardSize, std::string windowName = "");

    void addPoints(const std::vector<cv::Point2f> &imageCorners, const std::vector<cv::Point3f> &objectCorners);

    double calibrate(const cv::Size imageSize);
 
    void setCalibrationFlag(bool radial8CoeffEnabled = false, bool tangentialParamEnabled = false);

    cv::Mat remap(const cv::Mat &image);


    cv::Mat getCameraMatrix() { return cameraMatrix; }
    
    cv::Mat getDistCoeffs() { return distCoeffs; }
};

#endif
